<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	$_values			= array('title', 'body');	// which fields are stored in language variations
	

	$s = array('per_page' => 10, 'caption' => '');
	
	if (isset($DATA['component']['settings']['per_page']))
		$s['per_page'] = (int)$DATA['component']['settings']['per_page'];
	if (isset($DATA['component']['settings']['caption']))
		$s['caption'] = (int)$DATA['component']['settings']['caption'];



	
	
	if (($a = (int)param('edit')) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {
	
		switch (action(array('editor_save'))) {
		
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
				$temp = array();
	
				foreach($DATA['langs'] as $lang) {
				
					foreach($_values as $name) {
					
						$t = postdata($name);
						$temp[] = array_merge($_record, array('id_parent' => $a, 'name' => $name, 'value' => $t[$lang['text']], 'assoc' => $lang['text']));
				
					}
	
				}

				dataset('db_delete', tb('data'), "id_data=$_id_meta AND id_parent=$a");
				dataset('db_insert', tb('data'), $temp);

				$t = ($temp = trim($_POST['title'][LANG_DEF])) ? $temp : $DATA['object']['title'];
				dataset('db_update', tb('data'), array('name' => $t), "id=$a");
				

				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		
		}
	
	
	
	
	
		foreach($DATA['langs'] as $lang)
			$DATA['object']['data'][$lang['text']] = datafetch_array('meta', $_id_meta, $a, $lang['text']);
			
		if ($f = isImage($s['path'], $a))
			$DATA['object']['image'] = $s['path'].$f;

	}
	


	return false;
	
} else exit;

?>
